import {
  SELECT_CATEGORY,
  SELECT_TAG,
  EDIT_NOTELABEL,
  EDIT_AMOUNT,
} from "../actiontypes";

const initialState: NoteState = {
  category: "0",
  selectedTag: [],
  note: "",
  amount: 0,
};
//返回一个新的state
export default function (state = initialState, action: any) {
  switch (action.type) {
    case SELECT_CATEGORY:
      const { index } = action.payload;
      return {
        ...state,
        selectedTag: [],
        category: index,
      };
    case SELECT_TAG:
      const { tags } = action.payload;
      return {
        ...state,
        selectedTag: tags,
      };
    case EDIT_NOTELABEL:
      const { content } = action.payload;
      const newState = {
        ...state,
        note: content,
      };

      return newState;

    case EDIT_AMOUNT:
      const { amount } = action.payload;
      return {
        ...state,
        amount,
      };
    default:
      return state;
  }
}
